enum PIN_LIST {
    //% block="0"
    P0 = 0,
    //% block="1"
    P1 = 1,
    //% block="2" 
    P2 = 2,
    //% block="3"
    P3 = 3,
    //% block="4"
    P4 = 4
}


namespace led{
    //% color="#FF0000" 
    //% block="切换[PIN]引脚LED状态 [STATE]" blockType="command"
    //% PIN.shadow="dropdown" PIN.options="PIN_LIST" PIN.defl="PIN_LIST.P0"
    //% STATE.shadow="dropdown" STATE.options="LED_STATE" STATE.defl="LED_STATE.HIGH"
    export function ledToggle(parameter: any, block: any) {
        const pin = parameter.PIN.code;
        const state = parameter.STATE.code === "LED_STATE.HIGH" ? "HIGH" : "LOW";
        Generator.addCode(`digitalWrite(${pin}, ${state});`);
    }

    //% color="#FF4444"
    //% block="[PIN]引脚LED是否点亮？" blockType="boolean"
    //% PIN.shadow="dropdown" PIN.options="PIN_LIST" PIN.defl="PIN_LIST.P0"
    export function isLedOn(parameter: any, block: any) {
        const pin = parameter.PIN.code;
        Generator.addCode([`digitalRead(${pin}) == HIGH`, Generator.ORDER_UNARY_POSTFIX]);
    }
}